package com.wlhse.controller;

import com.wlhse.entity.AccidentRecordPojo;
import com.wlhse.service.AccidentRecordService;
import com.wlhse.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("AccidentRecordController")
@RequestMapping("/api/v1")
//事故
public class AccidentRecordController {
    @Resource
    private AccidentRecordService accidentRecordService;

    @RequestMapping(value = "/accident_record", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public R addAccidentRecord(@RequestBody(required = false) AccidentRecordPojo accidentRecordPojo) {
        return accidentRecordService.addAccidentRecord(accidentRecordPojo);
    }

    @RequestMapping(value = "/accident_record/{id}", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8")
    public R deleteAccidentRecord(@PathVariable int id) {
        return accidentRecordService.deleteAccidentRecord(id);
    }

    @RequestMapping(value = "/accident_record/{id}", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
    public R updateAccidentRecord(@PathVariable int id, @RequestBody AccidentRecordPojo accidentRecordPojo) {
        accidentRecordPojo.setId(id);
        return accidentRecordService.updateAccidentRecord(accidentRecordPojo);
    }

    //查by Id
    @RequestMapping(value = "/accident_record/{id}", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public R queryAccidentRecordsById(@PathVariable int id) {
        System.out.println("程序运行了0。。。。");
        return accidentRecordService.queryAccidentRecordsById(id);
    }

    //分页+条件查
    @RequestMapping(value = "/accident_record", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String queryAccidentRecordByCondition(@ModelAttribute AccidentRecordPojo accidentRecordPojo) {
        return accidentRecordService.queryAccidentRecordsByContiton(accidentRecordPojo);
    }
}
